package com.example.listviewdemo_1;

import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.listviewdemo_1.bean.Data;

import java.util.List;

public class MyAdapter extends BaseAdapter {
    private List<Data> jokeList;
    private  Context mContext;



    public MyAdapter(List<Data> newsTmp, Context context){
        jokeList=newsTmp;
        mContext = context;

    }
    @Override
    public int getCount() {  //返回有多少个子view
        return jokeList.size();
    }

    @Override
    public Object getItem(int position) {  //返回子view的数据的具体某个类的值
        return jokeList.get(position);
    }

    @Override
    public long getItemId(int position) {  //返回子view的当前位置的id
        return position;
    }


    //具体获取子view的布局
    @Override
    public View getView(final int position, View view, ViewGroup viewGroup) {

        ViewHolder viewHolder;
        Log.e("position",position+"");
        if(view ==null){
            view = View.inflate(mContext,R.layout.item_xiaohua,null);//找到子view布局
            viewHolder = new ViewHolder();
            // viewHolder.mPhoto = (ImageView)view.findViewById(R.id.photo);
            viewHolder.mTextView = view.findViewById(R.id.item_tv_content);
            viewHolder.mTextView_Updatetime =view.findViewById(R.id.item_tv_updatetime);
            view.setTag(viewHolder);
            Log.e("view","为空");
        }else {
            Log.e("view","复用，不为空");

            viewHolder = (ViewHolder) view.getTag();
        }
        viewHolder.mTextView.setText(jokeList.get(position).getContent());

        viewHolder.mTextView_Updatetime.setText(jokeList.get(position).getUpdatetime());

        return view;
    }
    class ViewHolder{
        TextView mTextView;
        TextView mTextView_Updatetime;


    }

}
